package com.michale.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.michale.common.domain.tool.JobEntity;
import com.michale.common.utils.Date.DateUtils;
import com.michale.common.utils.security.SecurityUtils;
import com.michale.system.mapper.tool.JobMapper;
import com.michale.system.service.JobService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Michale
 * @apiNote 定时任务调度 业务层
 */
@Service("jobService")
public class JobServiceImpl extends ServiceImpl<JobMapper, JobEntity> implements JobService {

    /**
     * 查询定时任务调度
     *
     * @param jobId 定时任务调度主键
     * @return 定时任务调度
     */
    @Override
    public JobEntity selectJobByJobId(Long jobId) {
        return baseMapper.selectJobByJobId(jobId);
    }

    /**
     * 查询定时任务调度列表
     *
     * @param jobEntity 定时任务调度
     * @return 定时任务调度
     */
    @Override
    public List<JobEntity> selectJobList(JobEntity jobEntity) {
        return baseMapper.selectJobList(jobEntity);
    }

    /**
     * 新增定时任务调度
     *
     * @param jobEntity 定时任务调度
     * @return 结果
     */
    @Override
    public int insertJob(JobEntity jobEntity) {
        jobEntity.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insertJob(jobEntity);
    }

    /**
     * 修改定时任务调度
     *
     * @param jobEntity 定时任务调度
     * @return 结果
     */
    @Override
    public int updateJob(JobEntity jobEntity) {
        jobEntity.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateJob(jobEntity);
    }

    /**
     * 批量删除定时任务调度
     *
     * @param jobIds 需要删除的定时任务调度主键
     * @return 结果
     */
    @Override
    public int deleteJobByJobIds(Long[] jobIds) {
        return baseMapper.deleteJobByJobIds(jobIds);
    }

    /**
     * 修改定时任务调度状态
     *
     * @param jobEntity 修改参数
     */
    @Override
    public int changeStatus(JobEntity jobEntity) {
        jobEntity.setUpdateBy(SecurityUtils.getUsername());
        return baseMapper.updateJob(jobEntity);
    }

    /**
     * 删除定时任务调度信息
     *
     * @param jobId 定时任务调度主键
     * @return 结果
     */
    @Override
    public int deleteJobByJobId(Long jobId) {
        return baseMapper.deleteJobByJobId(jobId);
    }
}
